package com.fxcalibre.icons;

import java.io.File;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import com.fxcalibre.utils.FileUtils;

public class ImageLoader
{

	public static ImageView getImageView(String icon)
	{
		return new ImageView(new Image(ImageLoader.class.getResourceAsStream(icon)));
	}

	public static ImageView getImageView(String icon, int size)
	{
		return new ImageView(new Image(ImageLoader.class.getResourceAsStream(icon), size, size, false, false));
	}

	public static ImageView getPersonImage(int personId)
	{
		return new ImageView(new Image(ImageLoader.class.getResourceAsStream("noFotoName.gif")));
	}

	public static ImageView getPersonImage(int personId, int size)
	{
		File imgsDir = FileUtils.getImgsDir();
		File imgFile = new File(imgsDir, personId + ".jpg");
		if(imgFile.exists())
		{
			return new ImageView(new Image(imgFile.toURI().toString(), size, size, false, false));
		}else
		{
			return new ImageView(new Image(ImageLoader.class.getResourceAsStream("noFotoName.gif"), size, size, false, false));
		}
	}

}
